#pragma once

#include "UnmarshallAction.h"

#include "Classifier.h"
#include "InputPin.h"
#include "OutputPin.h"

namespace uml {

UnmarshallAction::UnmarshallAction(const QString& umlType)
    : Action(umlType) {}

void UnmarshallAction::fromJson(const QJsonObject& json, QStringList& errorList) {
    if (json.isEmpty()) {
        return;
    }

    Action::fromJson(json, errorList);
    object_ = JsonSerializable::create<InputPin>(json.value("object"), errorList);

    JsonSerializable::fromJsonArray(results_, "results", json, errorList);
    unmarshallType_ = JsonSerializable::create<Classifier>(json.value("unmarshallType"), errorList);

}

void UnmarshallAction::toJson(QJsonObject& json) {
    Action::toJson(json);
    if (object_) {
        QJsonObject object_json;
        object_->toJson(object_json);
        json.insert("object", object_json);
    }
    JsonSerializable::toJsonArray(results_, "results", json);
    if (unmarshallType_) {
        QJsonObject unmarshallType_json;
        unmarshallType_->toJson(unmarshallType_json);
        json.insert("unmarshallType", unmarshallType_json);
    }
}

/// <summary>
/// object getter
/// The InputPin that gives the object to be unmarshalled.
/// </summary>
shared_ptr<InputPin> UnmarshallAction::object() const {
    return object_;
}

/// <summary>
/// object setter
/// The InputPin that gives the object to be unmarshalled.
/// </summary>
void UnmarshallAction::setObject(shared_ptr<InputPin> value) {
    object_ = value;
}

/// <summary>
/// results getter
/// The OutputPins on which are placed the values of the StructuralFeatures of the
/// input object.
/// </summary>
vector<shared_ptr<OutputPin>>& UnmarshallAction::results() {
    return results_;
}

/// <summary>
/// unmarshallType getter
/// The type of the object to be unmarshalled.
/// </summary>
shared_ptr<Classifier> UnmarshallAction::unmarshallType() const {
    return unmarshallType_;
}

/// <summary>
/// unmarshallType setter
/// The type of the object to be unmarshalled.
/// </summary>
void UnmarshallAction::setUnmarshallType(shared_ptr<Classifier> value) {
    unmarshallType_ = value;
}

} // namespace uml
